<?php


namespace app\api\wxpay;

class H5
{
	public $WechatPaySdk;
	public function __construct($config)
	{
		$this->WechatPaySdk = new WechatPaySdk($config);
	}
	public function pay($out_trade_no, $amount, $description, $notify_url, $ip = "")
	{
		$amount = $amount * 100;
		$instance = $this->WechatPaySdk->instance();
		try {
			$resp = $instance->chain("/v3/pay/transactions/h5")->post(["json" => ["appid" => \strval($this->WechatPaySdk->appid), "mchid" => \strval($this->WechatPaySdk->merchant_id), "description" => \strval($description), "out_trade_no" => \strval($out_trade_no), "notify_url" => \strval($notify_url), "amount" => ["total" => \intval($amount)], "scene_info" => ["payer_client_ip" => $ip ? $ip : \think\facade\Request::ip(), "h5_info" => ["type" => "Wap"]]], "debug" => false]);
			return json_decode($resp->getBody(), true);
		} catch (\Exception $e) {
			if ($e instanceof \GuzzleHttp\Exception\RequestException && $e->hasResponse()) {
				$r = $e->getResponse();
				return $r->getBody();
			}
			return $e->getMessage();
		}
	}
}